﻿using Admin2024.Domain.Entity.System;
using Admin2024.Domain.IDomainService.System.IUserService;
using Admin2024.Domain.Interface;
using Admin2024.Domain.ObjValue;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Admin2024.Domain.DomainService.System.UserService
{
    public class PasswordManagementService : IPasswordManagementService
    {
        private readonly IRepository<AppUser> UserRep;

        public PasswordManagementService(IRepository<AppUser> repository)
        {
            UserRep = repository;
        }
        public async Task<DomainResult<string>> ResetPassword(Guid appUserId, string password)
        {
            var user = await UserRep.GetByIdAsync(appUserId);
            if (user == null)
            {
                return DomainResult<string>.Error("用户不存在");
            }

            if(password == "")
            {
                user.Password = "7777777";
            }
            else
            {
                user.Password = password;
            }
            await UserRep.UpdateAsync(user);
            return DomainResult<string>.Success("修改成功");
        }

        public async Task<DomainResult<string>> UpdatePassword(Guid appUserId,  string password)
        {
         
            var user = await UserRep.GetByIdAsync(appUserId);
            if (user == null)
            {
                return DomainResult<string>.Error("用户不存在");
            }
            var passwordw = password.Trim();
            user.Password = passwordw;

            await UserRep.UpdateAsync(user);
            return DomainResult<string>.Success("修改成功");
        }
    }
}
